package com.chenjie.crud.enums;

import lombok.Data;

@Data
public class ResponseBase {
    private Boolean status;
    private String message;
    private  Integer code;
    private Object  data;


    // 通用返回成功
    public static ResponseBase ok() {
        ResponseBase r = new ResponseBase();
        r.setStatus(ResultCodeEnum.SUCCESS.getSuccess());
        r.setCode(ResultCodeEnum.SUCCESS.getCode());
        r.setMessage(ResultCodeEnum.SUCCESS.getMessage());
        return r;
    }
    // 通用返回成功
    public static ResponseBase ok(Object o) {
        ResponseBase r = new ResponseBase();
        r.setStatus(ResultCodeEnum.SUCCESS.getSuccess());
        r.setCode(ResultCodeEnum.SUCCESS.getCode());
        r.setMessage(ResultCodeEnum.SUCCESS.getMessage());
        r.setData(o);
        return r;
    }


    // 通用返回失败，未知错误
    public static ResponseBase error() {
        ResponseBase r = new ResponseBase();
        r.setStatus(ResultCodeEnum.UNKNOWN_ERROR.getSuccess());
        r.setCode(ResultCodeEnum.UNKNOWN_ERROR.getCode());
        r.setMessage(ResultCodeEnum.UNKNOWN_ERROR.getMessage());
        return r;
    }

    // 设置结果，形参为结果枚举
    public static ResponseBase setResult(ResultCodeEnum result) {
        ResponseBase r = new ResponseBase();
        r.setStatus(result.getSuccess());
        r.setCode(result.getCode());
        r.setMessage(result.getMessage());
        return r;
    }
}
